namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Configuration.Models
{
    /// <summary>
    /// 数据库配置模型
    /// </summary>
    public class DatabaseConfig
    {
        /// <summary>
        /// 数据库类型
        /// </summary>
        public string Type { get; set; } = "SqlServer";

        /// <summary>
        /// 连接字符串
        /// </summary>
        public string ConnectionString { get; set; } = "";

        /// <summary>
        /// 连接超时时间（秒）
        /// </summary>
        public int ConnectionTimeout { get; set; } = 30;

        /// <summary>
        /// 命令超时时间（秒）
        /// </summary>
        public int CommandTimeout { get; set; } = 120;

        /// <summary>
        /// 启用敏感数据日志记录
        /// </summary>
        public bool EnableSensitiveDataLogging { get; set; } = false;
    }

    /// <summary>
    /// JWT 配置模型
    /// </summary>
    public class JwtConfig
    {
        /// <summary>
        /// 密钥
        /// </summary>
        public string SecretKey { get; set; } = "";

        /// <summary>
        /// 发行者
        /// </summary>
        public string Issuer { get; set; } = "";

        /// <summary>
        /// 受众
        /// </summary>
        public string Audience { get; set; } = "";

        /// <summary>
        /// 过期时间（分钟）
        /// </summary>
        public int ExpiryMinutes { get; set; } = 60;

        /// <summary>
        /// 刷新令牌过期时间（天）
        /// </summary>
        public int RefreshTokenExpiryDays { get; set; } = 7;
    }

    /// <summary>
    /// 缓存配置模型
    /// </summary>
    public class CacheConfig
    {
        /// <summary>
        /// 缓存类型（memory/redis）
        /// </summary>
        public string Type { get; set; } = "memory";

        /// <summary>
        /// 是否启用测试
        /// </summary>
        public bool TestEnabled { get; set; } = true;

        /// <summary>
        /// 测试TTL（秒）
        /// </summary>
        public int TestTTL { get; set; } = 60;

        /// <summary>
        /// 测试键前缀
        /// </summary>
        public string TestKeyPrefix { get; set; } = "cms_test_";

        /// <summary>
        /// Redis配置
        /// </summary>
        public RedisConfig Redis { get; set; } = new RedisConfig();
    }

    /// <summary>
    /// Redis 配置模型
    /// </summary>
    public class RedisConfig
    {
        /// <summary>
        /// Redis 连接字符串
        /// </summary>
        public string Url { get; set; } = "redis://localhost:6379";

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; } = "";

        /// <summary>
        /// 数据库编号
        /// </summary>
        public int Db { get; set; } = 0;

        /// <summary>
        /// 最大重试次数
        /// </summary>
        public int MaxRetries { get; set; } = 3;

        /// <summary>
        /// 重试延迟（毫秒）
        /// </summary>
        public int RetryDelay { get; set; } = 1000;

        /// <summary>
        /// 连接超时（毫秒）
        /// </summary>
        public int ConnectionTimeout { get; set; } = 5000;

        /// <summary>
        /// 命令超时（毫秒）
        /// </summary>
        public int CommandTimeout { get; set; } = 3000;
    }

    /// <summary>
    /// 安全配置模型
    /// </summary>
    public class SecurityConfig
    {
        /// <summary>
        /// 启用多因素身份验证
        /// </summary>
        public bool EnableMFA { get; set; } = true;

        /// <summary>
        /// 启用威胁检测
        /// </summary>
        public bool EnableThreatDetection { get; set; } = true;

        /// <summary>
        /// 启用设备指纹
        /// </summary>
        public bool DeviceFingerprintEnabled { get; set; } = true;

        /// <summary>
        /// CSRF 密钥
        /// </summary>
        public string CsrfSecret { get; set; } = "";

        /// <summary>
        /// 应用程序名称
        /// </summary>
        public string AppName { get; set; } = "CMS LowCode Platform";

        /// <summary>
        /// TOTP 发行者
        /// </summary>
        public string TotpIssuer { get; set; } = "CMS Platform";

        /// <summary>
        /// 会话密钥
        /// </summary>
        public string SessionSecret { get; set; } = "";

        /// <summary>
        /// 会话超时时间（秒）
        /// </summary>
        public int SessionTimeout { get; set; } = 86400;

        /// <summary>
        /// 最大登录尝试次数
        /// </summary>
        public int MaxLoginAttempts { get; set; } = 5;

        /// <summary>
        /// 锁定持续时间（秒）
        /// </summary>
        public int LockoutDuration { get; set; } = 900;

        /// <summary>
        /// 密码最小长度
        /// </summary>
        public int PasswordMinLength { get; set; } = 6;

        /// <summary>
        /// 需要强密码
        /// </summary>
        public bool RequireStrongPassword { get; set; } = true;

        /// <summary>
        /// JWT 配置
        /// </summary>
        public JwtConfig Jwt { get; set; } = new JwtConfig();

        /// <summary>
        /// 限流配置
        /// </summary>
        public RateLimitConfig RateLimit { get; set; } = new RateLimitConfig();
    }

    /// <summary>
    /// 限流配置模型
    /// </summary>
    public class RateLimitConfig
    {
        /// <summary>
        /// 启用限流
        /// </summary>
        public bool EnableRateLimit { get; set; } = true;

        /// <summary>
        /// 通用规则
        /// </summary>
        public List<RateLimitRule> GeneralRules { get; set; } = new List<RateLimitRule>();
    }

    /// <summary>
    /// 限流规则模型
    /// </summary>
    public class RateLimitRule
    {
        /// <summary>
        /// 端点
        /// </summary>
        public string Endpoint { get; set; } = "";

        /// <summary>
        /// 时间周期
        /// </summary>
        public string Period { get; set; } = "";

        /// <summary>
        /// 限制次数
        /// </summary>
        public int Limit { get; set; } = 0;
    }

    /// <summary>
    /// CORS 配置模型
    /// </summary>
    public class CorsConfig
    {
        /// <summary>
        /// 是否启用 CORS
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 允许的源
        /// </summary>
        public List<string> AllowedOrigins { get; set; } = new List<string>();

        /// <summary>
        /// 允许的方法
        /// </summary>
        public List<string> AllowedMethods { get; set; } = new List<string>();

        /// <summary>
        /// 允许的标头
        /// </summary>
        public List<string> AllowedHeaders { get; set; } = new List<string>();

        /// <summary>
        /// 允许凭证
        /// </summary>
        public bool AllowCredentials { get; set; } = true;
    }

    /// <summary>
    /// 文件上传配置模型
    /// </summary>
    public class FileUploadConfig
    {
        /// <summary>
        /// 存储类型
        /// </summary>
        public string StorageType { get; set; } = "Local";

        /// <summary>
        /// 最大文件大小（字节）
        /// </summary>
        public long MaxFileSize { get; set; } = 52428800; // 50MB

        /// <summary>
        /// 允许的扩展名
        /// </summary>
        public List<string> AllowedExtensions { get; set; } = new List<string>();

        /// <summary>
        /// 图片扩展名
        /// </summary>
        public List<string> ImageExtensions { get; set; } = new List<string>();

        /// <summary>
        /// 本地存储配置
        /// </summary>
        public LocalStorageConfig Local { get; set; } = new LocalStorageConfig();
    }

    /// <summary>
    /// 本地存储配置模型
    /// </summary>
    public class LocalStorageConfig
    {
        /// <summary>
        /// 根路径
        /// </summary>
        public string RootPath { get; set; } = "wwwroot/uploads";

        /// <summary>
        /// 基础URL
        /// </summary>
        public string BaseUrl { get; set; } = "/uploads";
    }

    /// <summary>
    /// 日志配置模型
    /// </summary>
    public class LoggingConfig
    {
        /// <summary>
        /// 日志级别配置
        /// </summary>
        public Dictionary<string, string> LogLevel { get; set; } = new Dictionary<string, string>();

        /// <summary>
        /// 安全日志配置
        /// </summary>
        public SecurityLogConfig SecurityLog { get; set; } = new SecurityLogConfig();

        /// <summary>
        /// 审计日志配置
        /// </summary>
        public AuditLogConfig AuditLog { get; set; } = new AuditLogConfig();

        /// <summary>
        /// 操作日志配置
        /// </summary>
        public OperationLogConfig OperationLog { get; set; } = new OperationLogConfig();
    }

    /// <summary>
    /// 安全日志配置模型
    /// </summary>
    public class SecurityLogConfig
    {
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 日志级别
        /// </summary>
        public string Level { get; set; } = "info";

        /// <summary>
        /// 日志路径
        /// </summary>
        public string Path { get; set; } = "./logs/security.log";

        /// <summary>
        /// 最大大小
        /// </summary>
        public string MaxSize { get; set; } = "10MB";

        /// <summary>
        /// 最大文件数
        /// </summary>
        public int MaxFiles { get; set; } = 10;
    }

    /// <summary>
    /// 审计日志配置模型
    /// </summary>
    public class AuditLogConfig
    {
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 日志路径
        /// </summary>
        public string Path { get; set; } = "./logs/audit.log";
    }

    /// <summary>
    /// 操作日志配置模型
    /// </summary>
    public class OperationLogConfig
    {
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enabled { get; set; } = true;

        /// <summary>
        /// 日志路径
        /// </summary>
        public string Path { get; set; } = "./logs/operation.log";
    }
}
